fix: stop default_from_dict from mutating the caller's data dict - #11931
Merged
anakin87 merged 1 commit intoJul 9, 2026
Merged
Conversation
|
@Vedant-Agarwal is attempting to deploy a commit to the deepset Team on Vercel. A member of the Team first needs to authorize it. |
default_from_dict took a reference to data["init_parameters"] and replaced serialized sub-objects (Secret, ComponentDevice, nested components) with their deserialized instances in place, corrupting the caller's dict and breaking a second deserialization of the same data. Copy init_parameters before mutating, matching PipelineBase.from_dict which already deep-copies data to avoid this. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Vedant-Agarwal
force-pushed
the
fix/default-from-dict-mutates-data
branch
from
July 9, 2026 09:40
af886f5 to
0bb1d24
Compare
Contributor
Coverage reportClick to see where and how coverage changed
This report was generated by python-coverage-comment-action |
||||||||||||||||||||||||
|
@/tmp/gh_comment_85.md |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related Issues
FileToFileContent) and fix: prevent Answer.from_dict methods from mutating their input dict #11908 (Answer.from_dict), this time at the core serialization utility every component flows through.Proposed Changes:
default_from_dict()took a reference todata["init_parameters"]and then, while auto-deserializing nested objects, replaced the serialized sub-dicts with their live instances in place:So after
Component.from_dict(data)(which routes throughdefault_from_dict), the caller'sdatais silently corrupted — its serializedSecret/ComponentDevice/ nested-component dicts are swapped for live objects. A second deserialization of the samedata, or any later re-serialization / comparison, then misbehaves.PipelineBase.from_dictalready deep-copiesdatabefore deserializing precisely to avoid this; the publicdefault_from_dict/component_from_dictutilities did not. The fix copiesinit_parametersbefore mutating it (shallow is enough — only its top-level keys are reassigned).How did you test it?
test_component_from_dict_does_not_mutate_input, which deserializes a dict containing a serializedSecretand asserts (a) the returned component is correct and (b) the input dict is unchanged (data == deepcopy(data)taken before the call). It fails onmain(the input'sapi_keysub-dict becomes anEnvVarSecret) and passes with the fix.python -m pytest test/core/test_serialization.py→ all green (23 tests).ruff check/ruff format --checkclean on both files.Notes for the reviewer
Minimal one-line change at the single choke point (
component_from_dictdelegates here), so it covers every path. This complements #11908's dataclass-level fix by closing the same leak in the core utility.This PR was written with the help of an AI assistant. I have reviewed the changes and run the relevant tests locally.
Checklist
fix:).